package org.example.sbdemo.converter;

import org.example.sbdemo.DTO.UserDTO;
import org.example.sbdemo.entity.User;

public class UserConverter {
    public static UserDTO UserConvert(User user) {
        //类型转化，从User类变为UserDTO类
        //注意，UserDTO类中隐藏了level，只有id，age，name，gender属性

        UserDTO userDTO = new UserDTO();
        userDTO.setId(user.getId());
        userDTO.setAge(user.getAge());
        userDTO.setGender(user.getGender());
        userDTO.setName(user.getUsername());

        return userDTO;

    }

    public static User UserConvert(UserDTO userDTO) {
        //类型转化，从UserDTO类变为User类
        //注意，UserDTO类中隐藏了level，只有id，age，name，gender属性
        //所以只需要提供id，age和gender即可

        User user = new User();
        user.setId(userDTO.getId());
        user.setAge(userDTO.getAge());
        user.setGender(userDTO.getGender());
        user.setUsername(userDTO.getName());

        return user;

    }
}
